<template>
	<view>
		<form @submit="formSubmit" @reset="formReset">
			<view v-for="(item,index) in formlists" class="uni-form-item uni-column">
				<view class="title">{{item.constitutionKey}}</view>
				<input class="uni-input" :name="item.constitutionValue" v-if="item.constitutionKey!='性别'" :placeholder="'请输入'+item.constitutionKey" />
				<radio-group :name="item.constitutionValue" v-else>
					<label v-for="(item,index) in sexType">
						<radio :value="item.dictValue" /><text>{{item.dictName}}</text>
					</label>
				</radio-group>
			</view>
			
			<view class="uni-btn-v">
				<button form-type="submit">提交</button>
			</view>
		</form>
	</view>
</template>

<script>
	var  graceChecker = require("../../common/graceChecker.js");
	export default {
		onLoad(){
			this.getInfo();
			this.getConList()
		},
		data() {
			return {
				formlists:[],
				sexType:uni.getStorageSync("sex_type")
			}
		},
		
		methods: {
			getInfo(){
				this.$req.getUserInfo().then(res=>{
					if(res){
						this.gotoIndex()
					}
				})
			},
			getConList(){
				this.$req.getConList().then(res=>{
					if(res.length>0){
						this.formlists = res
					}
				})
			},
			getDictlists(){
				this.$req.getDictLists().then(res=>{
					uni.setStorageSync("dict_type",res)
				})
			},
			getDictValue(){
				let i= {
					sysDictTypeValue:"USER_SEX",
					typeId:1
				}
				this.$req.getDictValue(i).then(res=>{
					uni.setStorageSync("sex_type",res)
				})
			},
			
			formSubmit(e){
				let formData = e.detail.value
				var rule = [
				    {name:"height", checkType : "string", checkRule:"1,3",  errorMsg:"身高不能为空"},
				    {name:"weight", checkType : "string", checkRule:"1,4",  errorMsg:"体重不能为空"},
				];
				var checkRes = graceChecker.check(formData, rule);
				if(!checkRes){
					uni.showToast({ title: graceChecker.error, icon: "none" });
					return false;
				}
				this.$req.setUserInfo(formData).then(res=>{
					if(res.code==200){
						this.gotoIndex();
					}
				})
			},
			gotoIndex(){
				uni.redirectTo({
					url: '../index/index.vue',
				});
			}
		},
		
	}
</script>

<style>
img{
	width: 100px;
	height: 100px;
}
</style>
